home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / games / sokosrc.zoo / readscre.c < prev    next >
C/C++ Source or Header  |  1991-01-25  |  2KB  |  59 lines

  1. #include <stdio.h>
  2. #include "sokoban.h"
  3.  
  4. extern short level, packets, savepack, rows, cols;
  5. extern char map[MAXROW+1][MAXCOL+1];
  6. extern POS ppos;
  7.  
  8. readscreen()
  9. {
  10.    FILE *screen;
  11.    char *fnam;
  12.    short j, c, ret = 0;
  13.  
  14.    fnam = malloc( strlen( SCREENPATH) + 11);
  15. #if ATARIST
  16.    sprintf( fnam, "%s\\screen.%d", SCREENPATH, level);
  17. #else
  18.    sprintf( fnam, "%s/screen.%d", SCREENPATH, level);
  19. #endif
  20.    if( (screen = fopen( fnam, "r")) == NULL)
  21.       ret = E_FOPENSCREEN;
  22.    else {
  23.       packets = savepack = rows = j = cols  = 0;
  24.       storepos( ppos, -1, -1);
  25.       while( (ret == 0) && ((c = getc( screen)) != EOF)) {
  26.          switch( c) {
  27.            case '\n':     map[rows++][j] = '\0';
  28.                           if( rows > MAXROW)
  29.                              ret = E_TOMUCHROWS;
  30.                           else {
  31.                              if( j > cols) cols = j;
  32.                              j = 0;
  33.                           }
  34.                           break;
  35.            case C_PLAYERSTORE:
  36.            case C_PLAYER: if( ppos.x != -1)
  37.                              ret = E_PLAYPOS1;
  38.                           else {
  39.                              storepos( ppos, rows, j);
  40.                              map[rows][j++] = c;
  41.                              if( j > MAXCOL) ret = E_TOMUCHCOLS;
  42.                           }
  43.                           break;
  44.            case C_SAVE:   savepack++;
  45.            case C_PACKET: packets++;
  46.            case C_WALL:
  47.            case C_STORE:
  48.            case C_GROUND: map[rows][j++] = c;
  49.                           if( j > MAXCOL) ret = E_TOMUCHCOLS;
  50.                           break;
  51.            default:       ret = E_ILLCHAR;
  52.         }
  53.       }
  54.       fclose( screen);
  55.       if( (ret == 0) && (ppos.x == -1)) ret = E_PLAYPOS2;
  56.    }
  57.    return( ret);
  58. }
  59.